/**
 * 数组切片
 * @param {Array} arr
 * @param {Number} begin
 * @param {Number} end
 */
export function slice(arr, begin = 0, end = arr.length) {
  if (arr.length === 0) {
    return []
  }

  begin = begin < 0 ? 0 : begin
  if (begin >= arr.length) {
    return []
  }

  end = end > arr.length ? arr.length : end
  if (end <= 0 || end <= begin) {
    return []
  }

  const result = []
  for (let i = begin; i < end; ++i) {
    result.push(arr[i])
  }
  return result
}
